<template>
  <div class="cmp-result-table" v-if="(data != null) && (data.length > 0)">
    <h3 @click="hide = !hide">
      <i v-if="hide" class="icon el-icon-plus" />
      <i v-else class="icon el-icon-minus" />
      {{ title }}  ({{ data.length }})
    </h3>
    <el-table
      v-if="!hide"
      :data="data"
    >
      <el-table-column
        label=""
        align="center"
        :width="50"
      >
        <template v-slot="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-for="i in Object.keys(columnMap)"
        :key="i"
        :prop="i"
        :label="columnMap[i]"
      />
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'CmpResultTable',
  props: {
    title: {
      type: String,
      required: true,
    },
    columnMap: {
      type: Object,
      required: true,
    },
    data: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      hide: false,
    }
  },
}
</script>

<style scoped lang="scss">
h3 {
  cursor: pointer;
}

.icon {
  margin-right: 0.5em;
  color: #409EFF;
}
</style>
